package com.mgq.juc.c1;

import lombok.extern.slf4j.Slf4j;

/**
 * @author MaGuangQi
 * 测试守护线程,守护线程是一种特殊的形式,只要其他非守护线程结束了,守护线程就会跟着结束
 * @date 2021-12-14 09:16
 **/
@Slf4j
public class TestDaemon {
    public static void main(String[] args) throws InterruptedException {

        Thread t1=new Thread(()->{
            while (true) {
                log.debug("开始运行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("运行结束");
            }

        });
        //守护进程
        t1.setDaemon(true);
        t1.start();
        Thread.sleep(1000);
        //主线程结束,守护进程也会结束
        log.debug("主线程运行结束");
    }
}
